#!/bin/sh
### asr安装脚本
#[root@sugon_test ~]# tree /home/admin/asr/oldAsr/
#/home/admin/asr/oldAsr/
#├── asr-collector-4.7.1-SNAPSHOT-physical.tar.gz
#├── asr-monitor-4.7.0-SNAPSHOT-physical.tar.gz
#└── asr-service-4.7.0-SNAPSHOT-physical.tar.gz
#
#0 directories, 3 files

#2022年4月21日 添加根目录变量-未测试
### 编辑变量
source_dir=/home/admin/asr/oldAsr/				#压缩包所在目录(绝对路径)
target_dir=/opt/				#解压目录(绝对路径)

zookeeper_ip=192.168.101.100:2181			#zookeeper IP地址:端口
zookeeper_net=192.168.101			#zookeeper 网段
group=asr				#服务统一组名

#根目录
asrServerExec=/opt/asr-service-4.7.0-SNAPSHOT/
asrCollectorExec=/opt/asr-collector-4.7.1-SNAPSHOT/
asrMonitorExec=/opt/asr-monitor-4.7.0-SNAPSHOT/

### 压缩包解压
for i in `ls ${source_dir}*.tar.gz`
do
	tar xvf ${i} -C ${target_dir}
done


### 修改配置文件
#asr-service
chmod +x ${asrServerExec}startup.sh
dos2unix ${asrServerExec}startup.sh
#参数：configAddr=192.168.101.242:2181
sed -i "s/^configAddr=*.*.*.*:*/configAddr=${zookeeper_ip}/g" ${asrServerExec}conf/asr-service.properties
#参数：registry.address=192.168.101.242:2181
sed -i "s/^registry.address=*.*.*.*:*/registry.address=${zookeeper_ip}/g"${asrServerExec}conf/asr-service.properties
#参数：asr.svr.group=asr
sed -i "s/asr.svr.group=[a-z]*/asr.svr.group=${group}/g" ${asrServerExec}conf/asr-service.properties

#asr-collector
chmod +x ${asrCollectorExec}startup.sh
dos2unix ${asrCollectorExec}startup.sh
#参数：configAddr=192.168.101.242:2181
sed -i "s/^configAddr=*.*.*.*:*/configAddr=${zookeeper_ip}/g" ${asrCollectorExec}conf/collector.properties
#参数：registry.address=192.168.101.242:2181
sed -i "s/^registry.address=*.*.*.*:*/registry.address=${zookeeper_ip}/g" ${asrCollectorExec}conf/collector.properties
#参数：asr.svr.group=asr
sed -i "s/asr.svr.group=[a-z]*/asr.svr.group=${group}/g" ${asrCollectorExec}conf/collector.properties
sed -i "s/^network.segment=*.*.*.*/network.segment=${zookeeper_net}/g" ${asrCollectorExec}conf/collector.properties

#asr-monitor
chmod +x ${asrMonitorExec}startup.sh
dos2unix ${asrMonitorExec}startup.sh
#参数：configAddr=192.168.101.242:2181
sed -i "s/^configAddr=*.*.*.*:*/configAddr=${zookeeper_ip}/g" ${asrMonitorExec}conf/monitor.properties
#参数：registry.address=192.168.101.242:2181
sed -i "s/^registry.address=*.*.*.*:*/registry.address=${zookeeper_ip}/g" ${asrMonitorExec}conf/monitor.properties
#参数：asr.svr.group=asr
sed -i "s/asr.svr.group=[a-z]*/asr.svr.group=${group}/g" ${asrMonitorExec}conf/monitor.properties
sed -i "s/^network.segment=*.*.*.*/network.segment=${zookeeper_net}/g" ${asrMonitorExec}conf/monitor.properties